import { getBbkz } from "../../api/cloudbase-bbkz";
import { msg } from "../../utils/layer";

const state = {
  version: "",
  context: "",
  update: "",
  versionChange: false,
};
const getters = {
  v_version: () => state.version,
  v_context: () => state.context,
  v_update: () => state.update,
  v_change: () => state.versionChange,
};
const mutations = {
  SET_VERSION: (a, data) => {
    state.version = data;
  },
  SET_CONTEXT: (a, data) => {
    state.context = data;
  },
  SET_UPDATE: (a, data) => {
    state.update = data;
  },
  SET_VERSIONCHANGE: (a, data) => {
    state.versionChange = data;
  },
};

const actions = {
  getbbkz: async ({ commit }) => {
    try {
      const res = await getBbkz();
      const { versoion, context, update } = res.data[0];
      commit("SET_VERSION", versoion);
      commit("SET_CONTEXT", context);
      commit("SET_UPDATE", update);
    } catch (e) {
      // eslint-disable-next-line no-console
      console.log(e);
      msg({
        msg: "版本控制接口异常",
        alert: true,
        type: "error",
      });
    }
  },
};

export default {
  namespaced: true,
  state,
  getters,
  mutations,
  actions,
};
